package com.itsci.assignment2;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class ShowTravel extends Activity {
	private TextView name;
	private TextView price;
	private TextView des;
	private TravelManager traMgr;
	private TravleBean traBean;
	private Button btnBack;
	private Button btnEdit;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.show_travel);
		name = (TextView)findViewById(R.id.textView_show_travel_name);
		price = (TextView)findViewById(R.id.textView_show_travel_price);
		des = (TextView)findViewById(R.id.textView_show_travel_des);
		Intent intent = getIntent();
		String intentName = intent.getStringExtra("name");
		traMgr = new TravelManager(ShowTravel.this, null, null, 1);
		traBean = traMgr.getByTravelId(intentName);
		name.setText(traBean.getName().toString());
		price.setText(traBean.getPrice()+"");
		des.setText(traBean.getdes().toString());
	
		btnBack = (Button)findViewById(R.id.button_show_travel_back);
		btnBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent back = new Intent(ShowTravel.this,ListTravel.class);
				startActivity(back);
			}
		});
		
		btnEdit = (Button)findViewById(R.id.button_show_travel_edit);
		btnEdit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent gotoEdit = new Intent(ShowTravel.this,EditTravel.class);
				gotoEdit.putExtra("name",name.getText().toString());
				gotoEdit.putExtra("price",price.getText().toString());
				gotoEdit.putExtra("des",des.getText().toString());
//				startActivity(gotoEdit);
				startActivityForResult(gotoEdit, 111);
			}
		});
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		Toast.makeText(getBaseContext(), Integer.toString(resultCode), Toast.LENGTH_SHORT).show();		
		if(resultCode ==111){		
			name.setText(data.getExtras().getString("name"));
			price.setText(data.getStringExtra("price"));
		}
	}

}
